<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise测试</title>
</head>

<body>
    <script type='module'>
        import axios from './axios.js'
        let promise = axios.get('data.php')
            //获取商品数据
            .then(goods => {
                let item = goods.sort(order('price', 'desc'))[1]
                return axios.get(`comment.php?id=${item.id}`)
            })
            //获取评论
            .then(comment => {
                console.log(comment)
            })
            .catch(error => {
                console.log(error)
            })

        function order(feild, type) {
            return (a, b) => {
                switch (type) {
                    case 'asc':
                        return a[feild] - b[feild];
                        break
                    case 'desc':
                        return b[feild] - a[feild];
                        break
                }
            }
        }
    </script>
</body>

</html>